package com.hn.vue.controller;

import com.hn.vue.param.RoleParam;
import com.hn.vue.param.UserParam;
import com.hn.vue.pojo.Menu;
import com.hn.vue.pojo.Role;
import com.hn.vue.service.RoleService;
import com.hn.vue.vo.PageVo;
import com.hn.vue.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * hanni
 * 2019/3/1 0001
 * 15:50
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/all")
    private List<Role> findRoleAll(){
        return  roleService.findRoleAll();
    }

    @GetMapping("/list")
    public PageVo<Role> roleList(RoleParam param){

        return roleService.findRoleList(param);
    }

    @PostMapping("/save")
    public ResponseVo save(Role role){
        try {
            roleService.saveRole(role);
        }catch (Exception e){

            return ResponseVo.error("角色编辑失败");
        }
        return ResponseVo.ok("角色编辑成功");
    }

    @GetMapping("/delete")
    public ResponseVo delete(String idd){

        try {
            roleService.updateDeleteFlag(idd);
        }catch (Exception e){

            return ResponseVo.error("角色编辑失败");
        }
        return ResponseVo.ok("角色编辑成功");
    }

    @GetMapping("/selectMenuIdsByRoleId/{roleId}")
    private List<Long> selectById(@PathVariable("roleId") Long roleId){

        return roleService.selectMenuIdsByRoleId(roleId);
    }

    @PostMapping("/updateRoleMenu")
    public ResponseVo updateRoleMenu(Long roleId,String menuIds){


        try {
            roleService.updateRoleMenu(roleId,menuIds);
        }catch (Exception e){

            return ResponseVo.error("授权失败了");
        }
        return ResponseVo.ok("授权成功");


    }




}
